/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package de.blitzcoder.collide.config.textarea;

import de.blitzcoder.collide.gui.IDEDialog;
import java.awt.Component;
import java.util.EventObject;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.event.CellEditorListener;
import javax.swing.table.TableCellEditor;

/**
 *
 * @author blitzcoder
 */
class TableEditor implements TableCellEditor {

    private TextAreaTab tab;
    
    public TableEditor(TextAreaTab tab) {
        this.tab = tab;
    }
    
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {

        // col == 2 is the preview column
        if (column == 2) {
            PreviewPanel pa = (PreviewPanel)value;

            Component comp = table;
            while (!(comp instanceof IDEDialog))
                comp = comp.getParent();

            StyleEditor editor = new StyleEditor(pa,tab,(IDEDialog)comp);
        }

        // Just return the component
        if (value instanceof String) {
            return new JLabel((String) value);
        } else if (value instanceof JComponent) {
            return (JComponent) value;
        } else {
            return new JLabel("error");
        }

    }

    public Object getCellEditorValue() {
        return "Error";
    }

    public boolean isCellEditable(EventObject anEvent) {
        return true;
    }

    public boolean shouldSelectCell(EventObject anEvent) {
        return true;
    }

    public boolean stopCellEditing() {
        return true;
    }

    public void cancelCellEditing() {
    }

    public void addCellEditorListener(CellEditorListener l) {
    }

    public void removeCellEditorListener(CellEditorListener l) {
    }
}